<template>
  <div class="top">
    <div class="left">
      <span class="lbtn" @click="goHome">首页</span>
    </div>
    <div class="center">
      <div class="title">智慧旅游可视化大数据平台</div>
    </div>
    <div class="right">
      <span class="rbtn">统计报告</span>
      <span class="time">当前时间: {{ time }}</span>
    </div>
  </div>
</template>
<script setup lang='ts'>
import { ref, onMounted, onBeforeUnmount } from 'vue'
// 点击首页按钮回到首页
import { useRouter } from 'vue-router';
import moment from 'moment'
// 存储当前的时间
let time = ref(moment().format('YYYY-MM-DD hh:mm:ss'))
// 获取路由器对象
let $router = useRouter()
// 按钮的点击回调
const goHome = () => {
  $router.push('/home')
}

let timer = 0
// 组件挂载完毕，实时更新当前时间
onMounted(() => {
  timer = setInterval(() => {
    // 定时器逻辑
    time.value = moment().format('YYYY年MM月DD日 hh:mm:ss')
  }, 1000);
})

onBeforeUnmount(() => {
  // 组件销毁前执行的操作，清除定时器
  clearInterval(timer);
});

</script>
<script lang="ts">
export default {
  name: 'Top'
}
</script>
<style scoped lang="scss">
.top {
  height: 40px;
  width: 100%;
  display: flex;
}

.left {
  flex: 1.5;
  background: url('../../images/dataScreen-header-left-bg.png') no-repeat;
  background-size: 100% 100%;

  .lbtn {
    width: 150px;
    height: 40px;
    float: right;
    background: url('../../images/dataScreen-header-btn-bg-l.png');
    line-height: 40px;
    text-align: center;
    color: #29fcff;
    font-size: 20px;
  }
}

.center {
  flex: 2;

  .title {
    width: 100%;
    height: 74px;
    background: url('../../images/dataScreen-header-center-bg.png');
    color: #29fcff;
    font-size: 30px;
    line-height: 74px;
    text-align: center;
  }
}

.right {
  flex: 1.5;
  background: url('../../images/dataScreen-header-left-bg.png') no-repeat;
  background-size: 100% 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .rbtn {
    width: 150px;
    height: 40px;
    background: url('../../images/dataScreen-header-btn-bg-r.png');
    line-height: 40px;
    text-align: center;
    color: #29fcff;
    font-size: 20px;
    float: left;
  }

  .time {
    color: #29fcff;
    font-size: 20px;
  }
}</style>